package com.kykj.kykjyzw.service.impl;

import com.kykj.kykjyzw.dao.AdminRoleDao;
import com.kykj.kykjyzw.entity.MenuViewEntity;
import com.kykj.kykjyzw.entity.UserRoleViewEntity;
import com.kykj.kykjyzw.service.AdminRoleService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminRoleServiceImpl  implements AdminRoleService {
    @Resource
    AdminRoleDao adminRoleDao;

    /**
     * 获取按钮列表
     * @param rolename 角色名
     * @param routename 路由名
     * @param start 起始位置
     * @param limit 每页行数
     * @return List
     */
    @Override
    public List<MenuViewEntity> getMenuList(String rolename, String routename, int start, int limit) {
        if (!rolename.equals("")){
            rolename="%"+rolename+"%";
        }
        if (!routename.equals("")){
            routename="%"+routename+"%";
        }
        return adminRoleDao.getMenuList(rolename,routename,start,limit);
    }

    /**
     * 获取总数
     * @param rolename 角色名
     * @param routename 路由名
     * @return
     */
    @Override
    public int getMenuListCountByName(String rolename, String routename) {
        if (!rolename.equals("")){
            rolename="%"+rolename+"%";
        }
        if (!routename.equals("")){
            routename="%"+routename+"%";
        }
        return adminRoleDao.getMenuListCountByName(rolename,routename);
    }

    /**
     * 获取总数
     * @return int
     */
    @Override
    public int getMenuListCount() {
        return adminRoleDao.getMenuListCount();
    }

    /**
     * 获取用户角色
     * @param rolename
     * @param uname
     * @param start
     * @param limit
     * @return
     */
    @Override
    public List<UserRoleViewEntity> getUserRoleList(String rolename, String uname, int start, int limit) {
        if (!rolename.equals("")){
            rolename="%"+rolename+"%";
        }
        if (!uname.equals("")){
            uname="%"+uname+"%";
        }
        return adminRoleDao.getUserRoleList(rolename,uname,start,limit);
    }

    /**
     * 获取总数(有条件)
     * @param rolename 角色名称
     * @param uname 用户名
     * @return int
     */
    @Override
    public int getUserRoleListCountByName(String rolename, String uname) {
        if (!rolename.equals("")){
            rolename="%"+rolename+"%";
        }
        if (!uname.equals("")){
            uname="%"+uname+"%";
        }
        return adminRoleDao.getUserRoleListCountByName(rolename,uname);
    }

    /**
     * 获取总数（无条件）
     * @return int
     */
    @Override
    public int getUserRoleListCount() {
        return adminRoleDao.getUserRoleListCount();
    }
}
